package com.example.controller;


import com.example.common.annotation.OperLog;
import com.example.common.enums.LogType;
import com.example.common.utils.R;
import com.example.system.entity.Department;
import com.example.system.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王鹤蒲
 * @since 2024-01-21
 */
@Api(tags = "科室信息API",description="提供科室信息相关的 REST API")
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private IDepartmentService iDepartmentService;


    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/selectAll",method= RequestMethod.GET)
    @ResponseBody
    public R selectAll(@RequestParam(defaultValue = "") String name) {
        return iDepartmentService.selectAll(name);
    }


    @OperLog(operation = "科室管理",type = LogType.ADD)
    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/save",method= RequestMethod.POST)
    @ResponseBody
    public R insert(@RequestBody Department department) {
        return iDepartmentService.insert(department);
    }


    @OperLog(operation = "科室管理",type = LogType.DELETE)
    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/delete/{id}",method= RequestMethod.DELETE)
    @ResponseBody
    public R deleteById(@PathVariable("id") Integer id) {
        return iDepartmentService.deleteById(id);
    }


    @OperLog(operation = "科室管理",type = LogType.BATCH_DELETE)
    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/deleteBatch",method= RequestMethod.POST)
    @ResponseBody
    public R deleteByIds(@RequestBody Integer[] ids) {
        return iDepartmentService.deleteByIds(ids);
    }


    @OperLog(operation = "科室管理",type = LogType.UPDATE)
    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/edit",method= RequestMethod.POST)
    @ResponseBody
    public R edit(@RequestBody Department department) {
        return iDepartmentService.edit(department);
    }


    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/findAll",method= RequestMethod.GET)
    @ResponseBody
    public R findAll(){
      return iDepartmentService.findAll();
    }


    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/selectSecondClassDepartmentInfosList",method= RequestMethod.GET)
    @ResponseBody
    public R selectSecondClassDepartmentInfosList() {
        return iDepartmentService.selectSecondClassDepartmentInfosList();
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value="/{departmentId}",method= RequestMethod.GET)
    @ResponseBody
    public R selectDepartmentInfoById(@PathVariable("departmentId") Integer departmentId) {
        return iDepartmentService.selectDepartmentInfoById(departmentId);
    }
}

